package top.suven.base.core.redis;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * redis Cluster enum 类实现
 * 
 * @author joven
 *
 */
public enum RedisClusterEnum {

	PROJECT_NAME(-1,"defaultRedisClusterClient"),
	/**
	 * <code>ONE_REDIS = 1;</code>
	 * <code>oneRedisClusterClient 为spring 注入对象key;</code>
	 * 
	 * <pre>
	 * 用户redis
	 * </pre>
	 */
	ONE_REDIS(1, "oneRedisClusterClient"),
	/**
	 * <code>TWO_REDIS = 2;</code>
	 * <code>twoRedisClusterClient 为spring 注入对象key;</code>
	 * <pre>
	 * gis 车辆管理
	 * </pre>
	 */
	TWO_REDIS(2, "twoRedisClusterClient"),
	/**
	 * <code>THREE_REDIS = 3;</code>
	 * <code>threeRedisClusterClient 为spring 注入对象key;</code>
	 * <pre>
	 * 商家端
	 * </pre>
	 */
	THREE_REDIS(3, "threeRedisClusterClient"),

	/**
	 * <code>FOUR_REDIS = 4;</code>
	 * <code>fourRedisClusterClient 为spring 注入对象key;</code>
	 * <pre>
	 * 快递端
	 * </pre>
	 */
	FOUR_REDIS(4, "fourRedisClusterClient"),
	/**
	 * <code>FIVE_REDIS = 5;</code>
	 * <code>fiveRedisClusterClient 为spring 注入对象key;</code>
	 * <pre>
	 * 繁星 CDN
	 * </pre>
	 */
	FIVE_REDIS(5, "fiveRedisClusterClient"),

	/**
	 * <code>SIX_REDIS = 6;</code>
	 * <code>sixRedisClusterClient 为spring 注入对象key;</code>
	 * <pre>
	 * 移动直播
	 * </pre>
	 */
	SIX_REDIS(6, "sixRedisClusterClient"),

	SEVEN_REDIS(7, "sevenRedisClusterClient"),
	EIGHT_REDIS(8, "eightRedisClusterClient"),
	NINE_REDIS(9, "nineRedisClusterClient"),
	TEN_REDIS(10, "tenRedisClusterClient"),

	;


	
	private static Map<String, RedisClusterEnum> typeMap = new HashMap<>();
	private static Map<Integer, RedisClusterEnum> indexMap = new HashMap<>();

	static {

		for (RedisClusterEnum type : values()) {
			typeMap.put(type.name(), type);
			indexMap.put(type.getIndexKey(), type);
		}
	}

	private final int indexKey;
	private final String indexValue;
	

	RedisClusterEnum(int indexKey, String indexValue) {
		this.indexKey = indexKey;
		this.indexValue = indexValue;
	}

	public final int getIndexKey() {
		return indexKey;
	}

	public String getValue() {
		return indexValue;
	}


	public String toLowerName(){
		String[] t = name().split("_",2);
		if( null != t && t.length == 2){
			return t[0].toLowerCase();
		}return "";
	}

	public static Collection<RedisClusterEnum>  getRedisClusters(){
		if(typeMap == null || typeMap.isEmpty()){
			for (RedisClusterEnum type : values()) {
				typeMap.put(type.name(), type);
				indexMap.put(type.getIndexKey(), type);
			}
		}
		return typeMap.values();
	}
	
	
	public static RedisClusterEnum findByNumType(int numType) {
		RedisClusterEnum rc = indexMap.get(numType);
		if(null != rc ){
			return rc;
		}
		return PROJECT_NAME;
		
	}


}
